<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>

		<p>计数: <span id="span"></span></p>
		<button onclick="startWorker()">开始计数</button>
		<button onclick="stopWorker()">停止计数</button>

		<script>
			var w;
			function startWorker() {
				//检测浏览器是否支持 Web Worker
				if (typeof(Worker) !== "undefined") {
					if(typeof(w) == "undefined"){
						w = new Worker("../js/demo_workers.js");
					}
					w.onmessage = function(event){
						document.getElementById("span").innerHTML = event.data;
					}
				} else {
					console.error("抱歉!Web Worker不支持");
				}

			}
			
			function stopWorker(){
				w.terminate();
				w = undefined;
			}
		</script>
	</body>
</html>